#!/bin/bash
# 初始化脚本

function is_install(){
    name="$1"
    if ! type "${name}" >/dev/null 2>&1;then
        echo " 未安装 ${name} "
        return 1
    else
        echo " 已安装 ${name}"
        return 0
    fi
}

function install_git(){
    if ! is_install git ;then
        echo " 安装 git"
        sudo apt install git -y
        echo " 配置 git"
        git config --global user.name "rechie"
        git config --global user.email "502117806@qq.com"
    fi 
}

function install_sshd(){
    if ! is_install sshd ;then
        echo " 安装 sshd"
        sudo apt install openssh-server -y
    fi 
}

function install_vim(){
    if ! is_install vim ;then
        echo " 安装 vim"
        sudo apt install vim -y
    fi 
}

function install_pip () {
    if ! is_install pip ;then
        echo " 安装 pip"
        sudo apt install python3-pip -y
    fi 
}


function config_pip(){
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
}

function main(){
    sudo apt update
    install_git
    install_sshd
    install_vim
    install_pip
    config_pip
}

main